home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / xv_pc16a.zip / XVTEST.C < prev   
C/C++ Source or Header  |  1994-04-22  |  9KB  |  322 lines

  1. /*
  2. Test program for the PC-XView interface in C/C++
  3. By Antonio Carlos Moreirao de Queiroz - acmq@coe.ufrj.br
  4. Version 1.0a - 19/04/94
  5.  
  6. Make a project with mickey.obj, xview.obj, and xvtest.c.
  7. Use Turbo C++ 1.0 or more recent version.
  8. Set the memory model to "huge".
  9. Set linking with floating point and graphics libraries.
  10. Set the "C++ extensions only" option, or use the objects in XVCPP.ZIP and
  11. compile as a C++ program (with Borland C++ 3.1 or later version).
  12. Set the environment variable TCBGI to where are the BGI drivers with the
  13. correct version (the ones in xv_pc*.zip do not work with some compilers).
  14. Set the environment variable BMP to where are the ".bmp" files.
  15. It is not necessary if the .bgi and .bmp files are in the current directory.
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <xview.h>
  20. #include <graphics.h>
  21. #include <string.h>
  22. #include <notice.h>
  23.  
  24. int color=RED;
  25. char buf[200];
  26.  
  27. /* Declaration of the interface objects */
  28. Xv_opaque menu1;
  29. Xv_opaque frame1,tty1,button1,button2,button3,
  30.   button4,button5,text2,text3,text4,
  31.   button6;
  32. Xv_opaque frame2,canvas1,message1;
  33. Xv_opaque frame3,setting1,setting2,setting3,button7,message2;
  34.  
  35. /* Callback procedures */
  36.  
  37. void Open1(Xv_opaque obj)
  38. {
  39.   /* Notify handler for button1 */
  40.   open_window(frame2);
  41. }
  42.  
  43. void Open2(Xv_opaque obj)
  44. {
  45.   /* Notify handler for button2 */
  46.   open_window(frame3);
  47. }
  48.  
  49. void Quit(Xv_opaque obj)
  50. {
  51.   /* Notify handler for button3 */
  52.   xv_end=notice("Exit to DOS?");
  53. }
  54.  
  55. void Icon1(Xv_opaque obj)
  56. {
  57.   /* Notify handler for button4 */
  58.   ttysw_output(tty1,"XView-PC\r\nBy Antonio C. M. de Queiroz\r\n");
  59. }
  60.  
  61. void Icon2(Xv_opaque obj)
  62. {
  63.   /* Notify handler for button5 */
  64.   ttysw_output(tty1,"UFRJ, Rio de Janeiro, Brazil\r\n");
  65. }
  66.  
  67. void EnterText(Xv_opaque obj)
  68. {
  69.   /* Notify handler for text2 */
  70.   sprintf(buf,"Text: %s\r\n",obj->v.stextfield.panel_value);
  71.   ttysw_output(tty1,buf);
  72. }
  73.  
  74. void EnterInt(Xv_opaque obj)
  75. {
  76.   /* Notify handler for text3 */
  77.   sprintf(buf,"Integer: %d\r\n",obj->v.stextfield.panel_int);
  78.   ttysw_output(tty1,buf);
  79. }
  80.  
  81. void EnterReal(Xv_opaque obj)
  82. {
  83.   /* Notify handler for text4 */
  84.   sprintf(buf,"Real: %g\r\n",obj->v.stextfield.panel_real);
  85.   ttysw_output(tty1,buf);
  86. }
  87.  
  88. void Icon3(Xv_opaque obj)
  89. {
  90.   /* Notify handler for button6 */
  91.   ttysw_output(tty1,"E-mail: acmq@coe.ufrj.br\r\n");
  92. }
  93.  
  94. void Close2(Xv_opaque obj)
  95. {
  96.   /* Notify handler for frame2 */
  97.   /* Notify handler for frame3 */
  98.   sprintf(buf,"Closed %s\r\n",obj->xv_label);
  99.   ttysw_output(tty1,buf);
  100. }
  101.  
  102. void Draw(Xv_opaque obj)
  103. {
  104.   /* Event handler for canvas1 */
  105.   sprintf(buf,"x:%d y:%d",ie_locx,ie_locy);
  106.   xv_set(message1,buf);
  107.   if (ie_shiftcode) {
  108.     setfillstyle(SOLID_FILL,color);
  109.     bar(ie_locx-5,ie_locy-5,ie_locx,ie_locy);
  110.   }
  111. }
  112.  
  113. void Set1(Xv_opaque obj)
  114. {
  115.   /* Notify handler for setting1 */
  116.   /* Notify handler for setting1 */
  117.   sprintf(buf,"Selection=%d\r\n",obj->v.ssetting.sel_setting);
  118.   ttysw_output(tty1,buf);
  119. }
  120.  
  121. void ChangeColor(Xv_opaque obj)
  122. {
  123.   /* Notify handler for setting3 */
  124.   switch (obj->v.ssetting.sel_setting) {
  125.     case 1: color=RED; break;
  126.     case 2: color=GREEN; break;
  127.     case 3: color=BLUE;
  128.   }
  129. }
  130.  
  131. void Options(Xv_opaque obj)
  132. {
  133.   /* Notify handler for menu1 */
  134.   switch (obj->v.smenu.sel_menu) {
  135.     case 1: /* close 1 */; close_window(frame1); break;
  136.     case 2: /* close 2 */; close_window(frame2); break;
  137.     case 3: /* close 3 */; close_window(frame3); break;
  138.     case 4: /* open 1 */; open_window(frame1); break;
  139.     case 5: /* open 2 */; open_window(frame2); break;
  140.     case 6: /* open 3 */; open_window(frame3); break;
  141.     case 7: /* quit */; xv_end=1; break;
  142.     case 8: /* more... */; break;
  143.     case 9: /* memory */
  144.       if (frame1->v.sframe.mapped && frame1->v.sframe.Pw!=NULL) {
  145.     sprintf(buf,"Memory used by window 1: %ul\r\n",frame1->v.sframe.areaw);
  146.     ttysw_output(tty1,buf);
  147.       }
  148.       if (frame2->v.sframe.mapped && frame2->v.sframe.Pw!=NULL) {
  149.     sprintf(buf,"Memory used by window 2: %ul\r\n",frame2->v.sframe.areaw);
  150.     ttysw_output(tty1,buf);
  151.       }
  152.       if (frame3->v.sframe.mapped && frame3->v.sframe.Pw!=NULL) {
  153.     sprintf(buf,"Memory used by window 3: %ul\r\n",frame3->v.sframe.areaw);
  154.     ttysw_output(tty1,buf);
  155.       }
  156.       sprintf(buf,"Memory left: %ul\r\n",coreleft());
  157.       ttysw_output(tty1,buf);
  158.       break;
  159.   }
  160. }
  161.  
  162. void ListEvents(Xv_opaque obj)
  163. {
  164.   /* Event handler for message2 */
  165.   sprintf(buf,"Event: %d",ie_code);
  166.   xv_set(message2,buf);
  167. }
  168.  
  169. void main()
  170. {
  171.   /* Inicialization */
  172.   use_palette=1;
  173.   xv_init(0,0);
  174.   /* Menu creation */
  175.   /* Menu for frame1 */
  176.   /* Menu for frame2 */
  177.   /* Menu for frame3 */
  178.   /* Submenu for item 8 of 'menu1' */
  179.   menu1=xv_create(menu);
  180.     strcpy(menu1->xv_label,"menu");
  181.     item_create("close 1");
  182.     item_create("close 2");
  183.     item_create("close 3");
  184.     item_create("open 1");
  185.     item_create("open 2");
  186.     item_create("open 3");
  187.     item_create("quit");
  188.     item_create("more...");
  189.     item_create("memory");
  190.     /* Just for demonstration. Recursive menus can damage the screen */
  191.     menu1->v.smenu.item_submenu[7]=menu1;
  192.     menu1->v.smenu.sel_menu=1;
  193.     menu1->notify_handler=(xv_handler)Options;
  194.   /* Interface objects creation */
  195.   frame1=xv_create(frame);
  196.     strcpy(frame1->xv_label,"XView-PC test program");
  197.     frame1->dx=218;
  198.     frame1->dy=162;
  199.     frame1->v.sframe.dxmin=218;
  200.     frame1->v.sframe.dymin=162;
  201.     frame1->menu_name=menu1;
  202.     frame1->v.sframe.adjust_exit=0;
  203.   tty1=xv_create(tty);
  204.     tty1->v.scanvas.can_yext=0; tty1->dy=42;
  205.   button1=xv_create(button);
  206.     strcpy(button1->xv_label,"popup 2..");
  207.     button1->y=46;
  208.     button1->notify_handler=(xv_handler)Open1;
  209.   button2=xv_create(button);
  210.     strcpy(button2->xv_label,"popup 3..");
  211.     button2->y=61;
  212.     button2->notify_handler=(xv_handler)Open2;
  213.   button3=xv_create(button);
  214.     strcpy(button3->xv_label,"quit");
  215.     button3->y=76;
  216.     button3->notify_handler=(xv_handler)Quit;
  217.   button4=xv_create(button);
  218.     strcpy(button4->xv_label,"xview.bmp");
  219.     button4->x=80;
  220.     button4->y=46;
  221.     button4->v.sbutton.icon_label=1;
  222.     button4->notify_handler=(xv_handler)Icon1;
  223.   button5=xv_create(button);
  224.     strcpy(button5->xv_label,"brasil.bmp");
  225.     button5->x=126;
  226.     button5->y=46;
  227.     button5->v.sbutton.icon_label=1;
  228.     button5->notify_handler=(xv_handler)Icon2;
  229.   text2=xv_create(textfield);
  230.     strcpy(text2->xv_label,"Text:");
  231.     text2->y=91;
  232.     text2->notify_handler=(xv_handler)EnterText;
  233.   text3=xv_create(textfield);
  234.     strcpy(text3->xv_label,"Integer:");
  235.     text3->y=106;
  236.     text3->v.stextfield.value_length=17;
  237.     text3->v.stextfield.field_type=int_field;
  238.     text3->notify_handler=(xv_handler)EnterInt;
  239.   text4=xv_create(textfield);
  240.     strcpy(text4->xv_label,"Real:");
  241.     text4->y=121;
  242.     text4->v.stextfield.field_type=real_field;
  243.     text4->notify_handler=(xv_handler)EnterReal;
  244.   button6=xv_create(button);
  245.     strcpy(button6->xv_label,"email.bmp");
  246.     button6->x=171;
  247.     button6->y=46;
  248.     button6->v.sbutton.icon_label=1;
  249.     button6->notify_handler=(xv_handler)Icon3;
  250.   frame2=xv_create(frame);
  251.     strcpy(frame2->xv_label,"Window 2");
  252.     frame2->x=18;
  253.     frame2->y=20;
  254.     frame2->dx=218;
  255.     frame2->dy=160;
  256.     frame2->notify_handler=(xv_handler)Close2;
  257.     frame2->menu_name=menu1;
  258.   canvas1=xv_create(canvas);
  259.     canvas1->y=15;
  260.     canvas1->event_handler=(xv_handler)Draw;
  261.   message1=xv_create(message);
  262.     strcpy(message1->xv_label,"x: y:");
  263.   frame3=xv_create(frame);
  264.     strcpy(frame3->xv_label,"Window 3");
  265.     frame3->x=39;
  266.     frame3->y=42;
  267.     frame3->dx=216;
  268.     frame3->dy=86;
  269.     frame3->v.sframe.dymin=30;
  270.     frame3->notify_handler=(xv_handler)Close2;
  271.     frame3->menu_name=menu1;
  272.   setting1=xv_create(setting);
  273.     strcpy(setting1->xv_label,"exclusive");
  274.     item_create("1");
  275.     item_create("2");
  276.     item_create("3");
  277.     item_create("4");
  278.     item_create("5");
  279.     item_create("6");
  280.     item_create("7");
  281.     item_create("8");
  282.     item_create("9");
  283.     item_create("0");
  284.     setting1->v.ssetting.exclusive=1;
  285.     setting1->v.ssetting.sel_setting=1;
  286.     setting1->notify_handler=(xv_handler)Set1;
  287.   setting2=xv_create(setting);
  288.     strcpy(setting2->xv_label,"non excl.");
  289.     setting2->y=15;
  290.     item_create("a");
  291.     item_create("b");
  292.     item_create("c");
  293.     item_create("d");
  294.     item_create("e");
  295.     item_create("f");
  296.     item_create("g");
  297.     item_create("h");
  298.     item_create("i");
  299.     item_create("j");
  300.   setting2->notify_handler=(xv_handler)Set1;
  301.   setting3=xv_create(setting);
  302.     strcpy(setting3->xv_label,"color");
  303.     setting3->x=51;
  304.     setting3->y=30;
  305.     item_create("red");
  306.     item_create("green");
  307.     item_create("blue");
  308.     setting3->v.ssetting.exclusive=1;
  309.     setting3->v.ssetting.sel_setting=1;
  310.     setting3->notify_handler=(xv_handler)ChangeColor;
  311.   button7=xv_create(button);
  312.     strcpy(button7->xv_label,"events");
  313.     button7->y=45;
  314.     button7->event_handler=(xv_handler)ListEvents;
  315.   message2=xv_create(message);
  316.     message2->y=45;
  317.     message2->x=100;
  318.   xv_main_loop(frame1);
  319.   /* Exit */
  320.   restorecrtmode();
  321. }
  322.